#ifndef __OS_UART_H__
#define	__OS_UART_H__

#include "stm32f10x_conf.h"
#include "atos_fifo.h"
#include "ucos_ii.h"

typedef void (*os_uart_rec_callback_t)(uint8_t c);

typedef struct os_uart_config_t {
	char port_name[10];
	uint32_t baud_rate;
} os_uart_config_t;

typedef struct os_uart_device_t {
	uint8_t fd;
	os_uart_rec_callback_t callback;
	atos_fifo_t fifo;
	OS_EVENT *sem;
} os_uart_device_t;

typedef os_uart_device_t  *os_uart_fd_t;

#define		OS_UART_INVALID_FD		NULL
#define 		OS_UART_COUNT 			5

DLL_API void os_uart_init();
DLL_API os_uart_fd_t os_uart_open(
        const char * port_name,
        uint32_t baud_rate,
        os_uart_rec_callback_t callback,
        uint8_t *buf,
        uint16_t size);
DLL_API osa_result_t os_uart_close(os_uart_fd_t fd);
DLL_API uint16_t os_uart_send_byte(os_uart_fd_t fd, uint8_t byte);
DLL_API uint16_t os_uart_send_data(os_uart_fd_t fd, const void *buf, uint16_t len);
DLL_API uint16_t os_uart_receive_data(os_uart_fd_t fd, void *buf, uint16_t len);
DLL_API uint16_t os_uart_receive_byte(
        os_uart_fd_t fd,
        uint8_t *data);

void USART1_IRQHandler(void);
void USART2_IRQHandler(void);
void USART3_IRQHandler(void);
void UART4_IRQHandler(void);

#endif